import request from "@/api/request";
import type { SunnyResponse } from "@/types/sunnyResp";
import type {
  LoginUser,
  RegisterUser,
  SunnyUser,
} from "@/types/sunnyUser/type";
import type { AxiosPromise } from "axios";

export function loginApi(data: LoginUser): AxiosPromise<any> {
  return request({
    url: "/sunnyUser/login",
    method: "post",
    data,
  });
}

export function logoutApi() {
  return request({
    url: "/sunnyUser/logout",
    method: "get",
  });
}

export function registerApi(data: RegisterUser): Promise<SunnyResponse> {
  return request({
    url: "/sunnyUser/register",
    method: "post",
    data,
  });
}

export function getUserApi(): Promise<SunnyResponse<SunnyUser>> {
  return request({
    url: "/sunnyUser",
    method: "get",
  });
}

export function uploadAvatarApi(data: any) {
  return request({
    url: "/sunnyUser/avatar",
    method: "put",
    data,
  });
}

export function updateUserApi(data: SunnyUser) {
  return request({
    url: "/sunnyUser",
    method: "put",
    data,
  });
}

export function updatePasswordApi(data: LoginUser) {
  return request({
    url: "/sunnyUser/password",
    method: "put",
    data,
  });
}
